import 'package:flutter/material.dart';
import 'package:framework/data/model/notice_bean.dart';

/// 公告栏
class HomeNoticeWidget extends StatelessWidget {
  const HomeNoticeWidget({super.key});

  @override
  Widget build(BuildContext context) {
    List<NoticeBean> items = [
      NoticeBean(icon: "新闻", title: 'COM/NET域名维护通知', date: '10-17'),
      NoticeBean(icon: "公告", title: '关于COM/NET价格调整&部分优惠...', date: '10-18')
    ];

    List<Color> colors = [Color(0xFF0E69EC), Color(0xFFF68A19)];

    return Container(
      margin: EdgeInsets.symmetric(horizontal: 16),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(8),
        border: Border.all(
          color: Colors.grey,
          width: 0,
        ),
        boxShadow: [
          BoxShadow(
            color: Colors.grey,
            blurRadius: 0.5,
            offset: Offset(0, 1),
          )
        ],
      ),
      child: ListView.builder(
        padding: EdgeInsets.zero,
        shrinkWrap: true,
        physics: NeverScrollableScrollPhysics(),
        itemCount: items.length,
        itemBuilder: (context, index) {
          return _buildItemView(items[index], colors[index]);
        },
      ),
    );
  }

  Widget _buildItemView(NoticeBean data, Color color) {
    return Container(
      padding: const EdgeInsets.all(6),
      child: Row(
        children: [
          Container(
            padding:
            const EdgeInsets.only(left: 4, right: 4, top: 2, bottom: 2),
            decoration: BoxDecoration(
              color: color,
              borderRadius: BorderRadius.circular(4),
              boxShadow: [BoxShadow(color: Colors.grey, blurRadius: 1)],
            ),
            child: Text(data.icon.toString(),
                style: TextStyle(
                    fontSize: 12,
                    fontWeight: FontWeight.w400,
                    color: Colors.white)),
          ),
          SizedBox(width: 16),
          Text(data.title.toString(),
              style: TextStyle(
                  fontSize: 14,
                  fontWeight: FontWeight.w400,
                  color: Colors.black)),
          Expanded(child: SizedBox.fromSize()),
          Text(data.date.toString(),
              style: TextStyle(
                  fontSize: 12,
                  fontWeight: FontWeight.w400,
                  color: Colors.grey)),
        ],
      ),
    );
  }
}
